package com.example.zengyi;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import androidx.annotation.NonNull;

import java.util.List;

public class PrimeNumberAdapter extends ArrayAdapter<Integer> {

    public PrimeNumberAdapter(Context context, List<Integer> primes) {
        super(context, 0, primes);
    }

    @NonNull
    @Override
    public View getView(int position, View convertView, @NonNull ViewGroup parent) {
        if (convertView == null) {
            convertView = LayoutInflater.from(getContext()).inflate(R.layout.prime_item, parent, false);
        }

        Integer prime = getItem(position);
        TextView textView = convertView.findViewById(R.id.primeTextView);
        textView.setText(String.valueOf(prime));

        return convertView;
    }
}